package com.neuedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.entity.Nursecontent;
import com.neuedu.mapper.NursecontentMapper;
import com.neuedu.service.NursecontentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 护理内容 服务实现类
 * </p>
 *
 * @author wangyu
 * @since 2025-10-22
 */
@Service
public class NursecontentServiceImpl extends ServiceImpl<NursecontentMapper, Nursecontent> implements NursecontentService {

    @Override
    public IPage<Nursecontent> list(Integer pageNo, Integer pageSize, String name) {
        QueryWrapper<Nursecontent> wrapper = new QueryWrapper<>();
        if (StringUtils.isNoneBlank(name)) {
            wrapper.like("nursing_name", name);
        }
        wrapper.orderByDesc("id");
        return this.page(new Page<>(pageNo, pageSize), wrapper);
    }

    @Override
    public boolean check(String field, String value, Integer id) {
        QueryWrapper<Nursecontent> wrapper = new QueryWrapper<>();
        wrapper.eq(field, value);
        if (null != id) {
            wrapper.ne("id", id);
        }
        return this.count(wrapper) == 0;
    }

    @Override
    public List<Nursecontent> getList() {
        QueryWrapper<Nursecontent> wrapper = new QueryWrapper<>();
        wrapper.eq("status", 1);
        return this.list(wrapper);
    }

    @Override
    public List<Nursecontent> getByIds(List<Integer> ids) {
        QueryWrapper<Nursecontent> wrapper = new QueryWrapper<>();
        wrapper.in("id", ids);
        return this.list(wrapper);
    }
}
